package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.system.domain.IndexImage;
import com.ruoyi.system.domain.vo.*;
import com.ruoyi.system.mapper.IndexImageMapper;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysListingInformation;
import com.ruoyi.system.service.ISysListingInformationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 房源Controller
 * 
 * @author ruoyi
 * @date 2024-03-01
 */
@RestController
@RequestMapping("/wx/listing")
public class SysListingInformationController extends BaseController
{
    @Autowired
    private ISysListingInformationService sysListingInformationService;

    @Autowired
    private IndexImageMapper indexImageMapper;

    /**
     * 查询房源列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BaseEntity baseEntity)
    {
        return sysListingInformationService.selectSysListingInformationList();
    }

//    /**
//     * 导出房源列表
//     */
//    @PreAuthorize("@ss.hasPermi('listing:information:export')")
//    @Log(title = "房源", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, SysListingInformation sysListingInformation)
//    {
//        List<SysListingInformation> list = sysListingInformationService.selectSysListingInformationList(sysListingInformation);
//        ExcelUtil<SysListingInformation> util = new ExcelUtil<SysListingInformation>(SysListingInformation.class);
//        util.exportExcel(response, list, "房源数据");
//    }

    /**
     * 获取房源详细信息
     */
    @PostMapping("/detail")
    public AjaxResult detail(@RequestBody HomeVO homeVO)
    {
        return success(sysListingInformationService.selectSysListingInformationByListingId(homeVO));
    }

    /**
     * 新增房源
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysListingInformationVO sysListingInformation)
    {
        sysListingInformationService.insertSysListingInformation(sysListingInformation);
        return AjaxResult.success();
    }

    /**
     * 修改房源
     */
    @PreAuthorize("@ss.hasPermi('listing:information:edit')")
    @Log(title = "房源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysListingInformation sysListingInformation)
    {
        return toAjax(sysListingInformationService.updateSysListingInformation(sysListingInformation));
    }

    /**
     * 删除房源
     */
    @PreAuthorize("@ss.hasPermi('listing:information:remove')")
    @Log(title = "房源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{listingIds}")
    public AjaxResult remove(@PathVariable Long[] listingIds)
    {
        return toAjax(sysListingInformationService.deleteSysListingInformationByListingIds(listingIds));
    }

    /**
     * 首页轮播图
     * @return
     */
    @GetMapping("/indexImage")
    public AjaxResult indexImage(){
        List<IndexImage> list= indexImageMapper.selectList(null);
        return AjaxResult.success(list);

    }


    /**
     * 后台
     * @return
     */
    @GetMapping("/homeList")
    public TableDataInfo homeList(){

        return sysListingInformationService.homeList();

    }
}
